//
//  UIBarButtonItem+Extension.swift
//  Swift_Weibo
//
//  Created by Tim on 2019/8/13.
//  Copyright © 2019 Tim. All rights reserved.
//  UIBarButtonItem 扩展

import UIKit

extension UIBarButtonItem {
    /// 快速创建 barButtonItem
    ///
    /// - Parameters:
    ///   - title:      title
    ///   - fontSize:   文字大小，默认 16 号字
    ///   - target:     target
    ///   - action:     action
    ///   - isBack:     是否是返回按钮
    convenience init(title: String, fontSize: CGFloat = 16.0, target: AnyObject, action: Selector, isBack: Bool = false) {
        let btn = UIButton.textBtn(title: title, normalColor: UIColor.darkGray, highlightedColor: UIColor.orange, backgroundImg: nil)
        btn.addTarget(target, action: action, for: .touchUpInside)
        if isBack {
            let imgName = "navigationbar_back_withtext"
            btn.setImage(UIImage(named: imgName), for: .normal)
            btn.setImage(UIImage(named: imgName + "_highlighted"), for: .highlighted)
        }
        self.init(customView: btn)
    }
}
